import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);

import Login from '@/pages/login/index'
import Index from '@/pages/index/index'

import Home from '@/pages/home/index'
import Friend from '@/pages/friend/index'
import Mine from '@/pages/mine/index'
import Search from '@/pages/search/index'

/**
 * 创建 VueRouter 实例
 * 
 * @param routes 路由集合
 */
const router = new Router({
    routes: [
        { path: '/', redirect: '/login' },
        { path: '/login', component: Login },
        { path: '/index', component: Index, children: [
            { path: '/', redirect: '/home' },
            { path: '/home' , component: Home },
            { path: '/search', component: Search },
            { path: '/friend', component: Friend },
            { path: '/mine', component: Mine }
        ] }
    ]
})

/**
 * 前置拦截
 * @param to 前往的页面
 * @param from 来至哪里
 * @param next 放行函数
 */
router.beforeEach(function(to,from,next){
    /** 放行 */
    next();
})

/**
 * 后置拦截
 */
router.afterEach(function(){
    
})

export default router;